package com.arofoxmsn.model;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import com.arofoxmsn.model.comunication.MobilePhone;
import com.arofoxmsn.model.identifiedObject.MyObject;
import com.arofoxmsn.model.location.Location;
import com.arofoxmsn.model.profile.Profile;
import com.arofoxmsn.model.userstate.AbstractUserState;
import com.arofoxmsn.repository.ScopeAreaTable;

@Entity
public class User {
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name = "id", unique = true, nullable = false)
	private long id;
	
	private String displayName;
	
	@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	private Location currentLocation;
	
	@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	private Profile profile;
	
	@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	private MobilePhone mobile;
	
	@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	private MyObject myObject;
	
	@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	private AbstractUserState state;
	
	@Column(name="user_state") 
	@Enumerated(EnumType.ORDINAL) 
	private UserState userState;
	
	
	public User(String displayName, Location currentLocation,
			Profile profile, MobilePhone mobile, MyObject myObject,
			AbstractUserState state, UserState userState) {
		super();
		this.displayName = displayName;
		this.currentLocation = currentLocation;
		this.profile = profile;
		this.mobile = mobile;
		this.myObject = myObject;
		this.state = state;
		this.userState = userState;
	}
	
	public User(){super();}
	
	public long getId() {return id;}
	public void setId(long id) {this.id = id;}
	
	public String getDisplayName() {return displayName;}
	public void setDisplayName(String displayName) {this.displayName = displayName;}
	
	public Location getCurrentLocation() {return currentLocation;}
	public void setCurrentLocation(Location currentLocation) {this.currentLocation = currentLocation;}
	
	public Profile getProfile() {return profile;}
	public void setProfile(Profile profile) {this.profile = profile;}
	
	public MobilePhone getMobile() {return mobile;}
	public void setMobile(MobilePhone mobile) {this.mobile = mobile;}
	
	public MyObject getMyObject() {return myObject;}
	public void setMyObject(MyObject myObject) {this.myObject = myObject;}
	
	public AbstractUserState getState() {return state;}
	public void setState(AbstractUserState state) {this.state = state;}
	
	public UserState getUserState() {return userState;}
	public void setUserState(UserState userState) {this.userState = userState;}
	
	/**
	 * this method is in charge of create a bilaterally action
	 * when we create a relation of a user is in the scope of other one
	 * is the revertive method
	 * @param user
	 * @param distance
	 */
	public void createBilateralArea(User user, double distance){
		ScopeAreaTable table = new ScopeAreaTable();
		ScopeArea scopeArea = new ScopeArea();
		scopeArea.setOwner(user);
		scopeArea.setUserOnDistance(this);
		scopeArea.setDistance(distance);
		table.save(scopeArea);
	}
	
}
